/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * showArticlesByOffer.java
 *
 * Created on Nov 8, 2011, 2:37:19 AM
 */
package swa.e_store.userInterface;

import javax.swing.JTable;
import swa.e_store.DTO.ArticleDTO;
import swa.e_store.businessLogic.BL_Interface;
import swa.e_store.businessLogic.BL_RemoteFacade;

/**
 *
 * @author Stefan
 */
public class ShowArticlesByOfferPanel extends javax.swing.JPanel {
    
    private GraphicalUI gui;
    private BL_Interface bLogic;

    /** Creates new form showArticlesByOffer */
    public ShowArticlesByOfferPanel(GraphicalUI gui) {
        initComponents();
        
        this.gui = gui;
        this.bLogic = new BL_RemoteFacade();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        offerIdTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();

        jLabel1.setText("OfferId:");

        offerIdTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        offerIdTextField.setText("0");
        offerIdTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                offerIdTextFieldActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        jLabel2.setText("List articles by sale offer:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(offerIdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(212, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(offerIdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(208, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void offerIdTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_offerIdTextFieldActionPerformed

        int offerId = (new Integer(offerIdTextField.getText()).intValue());
        ArticleDTO artDTO = bLogic.getArticleTableByOffer(offerId);
        
        JTable table = new JTable(artDTO.getData(),artDTO.getColumnNames());
        
        gui.setContentPane(table);
        gui.pack();
    }//GEN-LAST:event_offerIdTextFieldActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField offerIdTextField;
    // End of variables declaration//GEN-END:variables
}
